import Item from './Item'

function createDiscount(item) {
  //代理模式
  return new Proxy(item, {
    get: function(target, key, receiver) {
      if(key == 'name') {
        return `${target[key]} 折扣`
      }
      if(key == 'price') {
        return target[key] * 0.8
      }
      return target[key]
    }
  })
}
//工厂模式
export default function(list, data) {
  if(data.discount) {
    data = createDiscount(data)
  }
  return new Item(list, data)
}